#ifndef IGSLIB_BUTTON_H
#define IGSLIB_BUTTON_H

#include <set>
#include "igslib_igpio.h"
#include "igslib_ibutton.h"

namespace igslib 
{
    class CButton:virtual public IButton
    {
        friend class CButtonManager;
        protected:
            int press_count;
            std::string name;
            std::set<IButtonEvent*> events;
            virtual void Update() { }
        public:
            CButton()
            {
                press_count = 0;
                name = "CButton";
            }
            virtual void SetEventHandler(IButtonEvent* value) { events.insert(value); }
            virtual std::string GetName() { return name; }
            virtual void SetName(const std::string& value) { name = value; }
            virtual bool IsPressed()
            {
                bool rtn = false;
                if (press_count > 0)
                {
                    rtn = true;
                }
                return rtn;
            }
            virtual bool IsPressDown()
            {
                bool rtn = false;
                if (press_count == 1)
                {
                    rtn = true;
                }
                return rtn;
            }
    };

    class CGPIOButton:virtual public CButton,virtual public IGPIOButton
    {
        protected:
            IGPIO* gpio;
        public:
            CGPIOButton();
			virtual void SetGPIO(IGPIO* value) {gpio=value;} 
            virtual void Update();
    };

    class CButtonManager:public IButtonManager
    {
        static IButtonManager* instance;
        public:
            static IButtonManager* GetInstance();
            virtual IGPIOButton* NewGPIOButton();
            virtual void Update();
    };
};

#endif
